package com.jungle;

import com.jungle.annotation.EnableFscCompensate;
import com.jungle.task.executor.DefaultCompensateTaskExecutor;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.lang.reflect.Type;
import java.util.Map;
import java.util.Objects;

/**
 * @author 李岩 at 2021/10/23.
 */
public class CompensateExecutorImportSelector implements ImportSelector {

    @Override
    public String[] selectImports(final AnnotationMetadata annotationMetadata) {
        final Map<String, Object> annotationAttributes =
            annotationMetadata.getAnnotationAttributes(EnableFscCompensate.class.getName());
         String compensateExecutor = DefaultCompensateTaskExecutor.class.getName();
        if (Objects.nonNull(annotationAttributes) && annotationAttributes.containsKey("compensateExecutor")) {
            compensateExecutor = ((Type)annotationAttributes.get("compensateExecutor")).getTypeName();
        }
        return new String[]{compensateExecutor};
    }
}
